package name.wilbur.course.db.bigone.dao.impl;

import name.wilbur.course.db.bigone.dao.BaseDAO;
import name.wilbur.course.db.bigone.dao.DAOFactory;
import name.wilbur.course.db.bigone.model.UserProfileView;
import name.wilbur.course.db.bigone.util.Checker;

public class UserProfileViewDAO extends BaseDAO implements IUserProfileViewDAO {

	public UserProfileViewDAO() {
		super(UserProfileView.class);
	}

	@Override
	public UserProfileView[] findByNameAndCity(String name, String cityName) {
		// get cityID by cityName
		ICityDAO cityDAO = (ICityDAO) DAOFactory.createDAO(CityDAO.class);
		int cityID = cityDAO.getPkByName(cityName);
		
		String where_clause = "CityID = '" + cityID + "'";
		if (Checker.notEmptyString(name))
			where_clause += " AND Name = '" + name + "'";
		UserProfileView[] userProfiles = (UserProfileView[]) findWhere(where_clause);
		return userProfiles;
	}
}
